*** Create Figure 5A ***

********************************************************************************

** read in .dta file **

use "${clean}/who_counts_analysis.dta", clear


** Run Honest DiD Event Study for 1945-1962 subset **

preserve
drop if YOB < 1945
drop if YOB > 1962

*Excluded Groups: Provinces formerly administered by Spain, non-residents, non-citizens, those born abroad, province partially in W. Sahara
drop if FR_Maroc!=1
drop if ma1994a_resident==2
drop if citizen==4
drop if nativity==2
drop if geo2alt_ma==504001391

gen byte D = (ANY_FOR == 1)
gen `:type year' Dyear = cond(D, YOB, 1950)

reghdfe MOB b1950.Dyear ec_total, absorb(Arabic Female geo2_ma YOB reg_fe) cluster(geo2_ma) noconstant
matrix list e(b)
label variable Dyear "year"

honestdid, pre(1/5) post(7/18) mvec(0.5(0.5)2)
honestdid, coefplot cached title("Registration")
graph save "${output}/graphs/MOB_HDID.gph", replace
graph export "${output}/graphs/MOB_HDID.png", replace

restore

* Honest DiD Test: Schooling, ANY FOR
preserve
drop if YOB < 1945
drop if YOB > 1962

*Excluded Groups: Provinces formerly administered by Spain, non-residents, non-citizens, those born abroad, province partially in W. Sahara
drop if FR_Maroc!=1
drop if ma1994a_resident==2
drop if citizen==4
drop if nativity==2
drop if geo2alt_ma==504001391

gen byte D = (ANY_FOR == 1)
gen `:type year' Dyear = cond(D, YOB, 1950)

reghdfe Schooling b1950.Dyear  n_schools52 n_classes52 n_students52, absorb(Arabic Female geo2_ma YOB reg_fe) cluster(geo2_ma) noconstant
matrix list e(b)
label variable Dyear "year"

honestdid, pre(1/5) post(7/18) mvec(0.5(0.5)2)
honestdid, coefplot cached title("Formal Schooling")
graph save "${output}/graphs/Schooling_HDID.gph", replace
graph export "${output}/graphs/Schooling_HDID.png", replace

restore

* Honest DiD Test: Years, ANY FOR
preserve
drop if YOB < 1945
drop if YOB > 1962

*Excluded Groups: Provinces formerly administered by Spain, non-residents, non-citizens, those born abroad, province partially in W. Sahara
drop if FR_Maroc!=1
drop if ma1994a_resident==2
drop if citizen==4
drop if nativity==2
drop if geo2alt_ma==504001391

gen byte D = (ANY_FOR == 1)
gen `:type year' Dyear = cond(D, YOB, 1950)

reghdfe EDU_YRS b1950.Dyear  n_schools52 n_classes52 n_students52, absorb(Arabic Female geo2_ma YOB reg_fe) cluster(geo2_ma) noconstant
matrix list e(b)
label variable Dyear "year"


honestdid, pre(1/5) post(7/18) mvec(0.5(0.5)2)
honestdid, coefplot cached title("Formal Schooling, Years")
graph save "${output}/graphs/YRS_HDID.gph", replace
graph export "${output}/graphs/YRS_HDID.png", replace

restore

* Honest DiD Test: Lit, ANY FOR
preserve
drop if YOB < 1945
drop if YOB > 1962

*Excluded Groups: Provinces formerly administered by Spain, non-residents, non-citizens, those born abroad, province partially in W. Sahara
drop if FR_Maroc!=1
drop if ma1994a_resident==2
drop if citizen==4
drop if nativity==2
drop if geo2alt_ma==504001391

gen byte D = (ANY_FOR == 1)
gen `:type year' Dyear = cond(D, YOB, 1950)

reghdfe French_Lit b1950.Dyear  n_schools52 n_classes52 n_students52, absorb(Arabic Female geo2_ma YOB reg_fe) cluster(geo2_ma) noconstant
matrix list e(b)
label variable Dyear "year"


honestdid, pre(1/5) post(7/18) mvec(0.5(0.5)2)
honestdid, coefplot cached title("French & Arabic Literacy")
graph save "${output}/graphs/LIT_HDID.gph", replace
graph export "${output}/graphs/LIT_HDID.png", replace

restore


** Output and Combine Figures **

graph combine "${output}/graphs/MOB_HDID.gph" "${output}/graphs/Schooling_HDID.gph" "${output}/graphs/YRS_HDID.gph" "${output}/graphs/LIT_HDID.gph"
graph save "${output}/graphs/Figure5A.gph", replace
graph export "${output}/graphs/Figure5A.png", replace
